#ifndef PARSER_H
#define PARSER_H
#include <QDebug>
#include <QObject>
#include <QFile>
#include <QString>
#include <QStringList>
#include <QtXml/QXmlReader>
#include <QtXml/QXmlInputSource>
#include <QXmlStreamReader>
#include <QtNetwork/QNetworkReply>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkRequest>
#include <QtXml/qdom.h>
#include <QtXml/QDomNode>
#include <QtXml/QDomCDATASection>

//#include<QDom
//#include <QtXml/qdom.h>
/*! \class parser
    \brief Classe du parser.

    En-tête du parser .
*/

class parser : public QObject
{
    Q_OBJECT
public:
    explicit parser(QObject *parent = 0);
    ~parser();
    //parser(const QString file);
    void parsefile(const QString content);

    void analyse_post(QXmlStreamReader& xml);
private :
    QString site;
    QString heures;
    QString minutes;
    QString secondes;
    QString message_content;
    QString site_name_board;
    QStringList messages;
    QStringList horloges;
    QStringList ids;
    QStringList usersagents;
    QStringList logins;
    QStringList plonk_liste;
    QStringList logins_copy;
    QString time;
    QString user_agent;
    QString pseudo;
    QString board_site;
    QRegExp const_name;
    QRegExp const_post;
    QRegExp const_time;
    QFile fichier_xml;
    QXmlStreamReader data;
    QXmlInputSource *second_parse;
    QXmlSimpleReader *parsing;
    QNetworkReply *reply;
    QDomDocument *domdocument;
    QDomElement root;
    QDomElement child;
    QDomElement second_child;
    bool order_posts_in_chrono;
    int i;
    int nb_users;
    //QDomDocument *dom_doc;
    //QDomElement elmnt;
    void parse_content(const QString data_xml);
    void mask_posts(QStringList list_bak, QStringList messages_list, QStringList users);
    void getpseudo(void);
    void gettime(void);
    void getmessage(void);
    void getuseragent(void);
    void openfile(const QString file);
    void failback_parser(QString content);
    int timer(int temps);
    void getlines(void);

    void closefile(void);

signals:
    void send_site_value(QString);
    void send_board_data_decoded(QString);
    void send_users_number(int);
    void parse_end(bool);
    void send_users_list(QStringList,QStringList);
    void send_user_agents_list(QStringList);
    void end_parse(void);
    void fail_parse(void);
    void send_namesite(QString);
    void emit_parsing_state(int);
public slots:
    void get_content_from_http(const QByteArray content);
    void bool_order_post(bool var);
    void affiche_board(bool ok);
    void parse_slot(const QByteArray value);
    void get_plonk_users(QStringList plonkusers);
    void get_content(void);
    //void get_network_reply(QNetworkReply);
    //void set_add(QString add);
    //void get_file_to_parse(QString);
    QString readline(int num);
    QString affiche_data(void);
    //QString readhorloge(int num);
    QString readua(int num);
    //QString readpseudo(int num);
    QString readmessage(int num);

private slots:
    void access_site_name(void);
    void manual_parsing(QString content);
};

#endif // PARSER_H
